package com.focusai.efairy.ui.adapter.dev;

import android.content.Context;
import android.view.View;

import com.focusai.efairy.R;
import com.focusai.efairy.model.project.ProjectItem;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerAdapter;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerViewHolder;

/**
 * Created by luo_guangwen on 2017/7/31.
 */

public class ProjectLocationAdapter extends BaseRecyclerAdapter<ProjectItem> {

    private int selectPostion = -1;
    private OnItemViewClickListener onItemViewClickListener;
    public ProjectLocationAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_project_location;
    }

    @Override
    protected void onBindBaseRecyclerViewHolder(final BaseRecyclerViewHolder holder, final int position) {
        final ProjectItem item = mList.get(position);
        holder.setText(R.id.tv_project_name, item.efairyproject_name);
        holder.setText(R.id.tv_project_adress, item.efairyproject_address);
        if (position == selectPostion){
            holder.getView(R.id.llayout_item).setBackgroundColor(mContext.getResources().getColor(R.color.bg_gray));
        }else {
            holder.getView(R.id.llayout_item).setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }
        holder.getView(R.id.llayout_item).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPostion = position;
                if (onItemViewClickListener != null){
                    onItemViewClickListener.onItemClick(holder,position);
                    notifyDataSetChanged();
                }
            }
        });
        holder.getView(R.id.ll_go_here).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPostion = position;
                if (onItemViewClickListener != null) {
                    onItemViewClickListener.onItemClickGoHere(item, position);
                }
            }
        });
    }

    public void setOnItemViewClickListener(OnItemViewClickListener onItemViewClickListener) {
        this.onItemViewClickListener = onItemViewClickListener;
    }

    /**
     * item点击事件回调接口
     */
    public  interface OnItemViewClickListener {
        void onItemClick(BaseRecyclerViewHolder holder,int position);
        void onItemClickGoHere(ProjectItem item, int position);
    }
}
